﻿using Caliburn.Micro;
using KouDai.Phone.Engine;
using KouDai.Phone.Helper;
using KouDai.Phone.Models;
using KouDai.Phone.Services;
using KouDai.Phone.Utils;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;

namespace KouDai.Phone.ViewModels
{
    public class ImageWallDevPageViewModel : KouDaiScreen
    {
        #region Fields

        private ObservableCollection<HoneyEntity> _honeyItems = new ObservableCollection<HoneyEntity>();
        private readonly INavigationService _navigationService;
        private long _minTimeStamp = 0;

        #endregion

        #region Constructor

        public ImageWallDevPageViewModel()
        {
            if (Execute.InDesignMode)
            {
                LoadDesignData();
            }
        }

        public ImageWallDevPageViewModel(INavigationService navigationService)
        {
            _navigationService = navigationService;
        }

        #endregion


        #region Properties

        public ObservableCollection<HoneyEntity> HoneyItems
        {
            get { return _honeyItems; }
            set
            {
                if (value != _honeyItems)
                {
                    _honeyItems = value;
                    this.NotifyOfPropertyChange(() => this.HoneyItems);
                }
            }
        }

        #endregion

        #region Method


        #region override

        public override void LoadDesignData()
        {
            base.LoadDesignData();
        }

        protected override void OnInitialize()
        {
            GetImageWall();
        }

        #endregion


        #region ExecuteMethod

        private async void GetImageWall()
        {
            BackData backData = await ServiceManager.GetImageWall("Combine_Default", 0);
            if (backData.IsSuccess)
            {
                List<HoneyEntity> honeyList = backData.ResposeData as List<HoneyEntity>;
                honeyList.ToObservableCollection<HoneyEntity>(this.HoneyItems);
                HoneyEntity lastEntity = honeyList[honeyList.Count - 1];
                this._minTimeStamp = lastEntity.Timestamp;
            }
            else
            {
                Debug.WriteLine(backData.Msg.ToString());
            }
        }

        #endregion

        #endregion

    }
}
